<template>
  <div class="board-column">
    <div class="board-column-header">
      {{ headerText }}
    </div>
    <draggable
      :list="list"
      v-bind="$attrs"
      class="board-column-content"
      :set-data="setData"
      @end="dragEnd"
      @add="onadd"
    >
      <div v-for="(item) in list" :key="item.id" class="board-item">
        <!-- <div style="height: 20px;"> -->
        <el-checkbox @change.capture="selected($event, item)" @click.stop.native="() => {}"
          ><span class="music">{{ item.name }}</span></el-checkbox
        >
        <!-- </div> -->
        <button style="width: 50px; height: 30px">删除</button>
      </div>
    </draggable>
  </div>
</template>

<script>
import { nextTick } from 'vue';
import draggable from 'vuedraggable';

export default {
  name: 'DragKanbanDemo',
  components: {
    draggable
  },
  props: {
    headerText: {
      type: String,
      default: 'Header'
    },
    options: {
      type: Object,
      default() {
        return {};
      }
    },
    list: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      selectedList: [], //已经选择的音乐数组
      //拖出源母元素下标
      ondragendIndex: '',
      //拖入母元素下标
      ondropIndex: '',
      //拖出子元素下标
      oldIndex: '',
      //拖入子元素下标
      newIndex: ''
    };
  },
  mounted() {
  },
  methods: {
    setData(dataTransfer) {
      // to avoid Firefox bug
      // Detail see : https://github.com/RubaXa/Sortable/issues/1012
      dataTransfer.setData('Text', '');
    },
    dragEnd(val) {
      // console.log('拖拽后的数组', this.list);
    },
    add(item) {
      // console.log('add', item.item);
    },
    //监听滑动添加时
    onadd(e) {
      // console.log('add', e);
      // 拖出子元素时的下表
      this.oldIndex = e.oldIndex;

      // 拖入子元素到新数组中的下表
      this.newIndex = e.newIndex;
      // console.log('移动的数据是:', this.list[this.oldIndex]);
    },
    //  //监听源母元素拖动下标
    //  onDrop(element, index) {
    //   this.ondropIndex = index;
    //   console.log("拖动元素到目标母元素的下标:", this.ondropIndex);
    // },
    selected(e, item) {
      item.isSelectd = !item.isSelectd;
      this.selectedList = this.list.filter((item) => {
        return item.isSelectd;
      });
      // console.log('已选择音乐的数组', this.selectedList);
    }
  }
};
</script>
<style lang="scss" scoped>
.board-column {
  min-width: 300px;
  min-height: 100px;
  height: auto;
  overflow: hidden;
  background: #f0f0f0;
  border-radius: 3px;

  .board-column-header {
    height: 50px;
    line-height: 50px;
    overflow: hidden;
    padding: 0 20px;
    text-align: center;
    background: #333;
    color: #fff;
    border-radius: 3px 3px 0 0;
  }

  .board-column-content {
    height: 500px;
    overflow-y: scroll;
    border: 1px solid red;
    min-height: 60px;
    display: flex;
    justify-content: flex-start;
    flex-direction: column;
    align-items: center;
    .board-item {
      display: flex;
      justify-content: space-between;
      cursor: pointer;
      width: 100%;
      height: 64px;
      margin: 5px 0;
      background-color: #fff;
      text-align: left;
      line-height: 54px;
      padding: 5px 10px;
      box-sizing: border-box;
      box-shadow: 0px 1px 3px 0 rgba(0, 0, 0, 0.2);
    }
    .music {
      display: block;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      width: 184px;
      height: 100%;
      // background-color: pink;
      box-sizing: border-box;
    }
  }
}

// :deep .el-checkbox__input.is-checked .el-checkbox__inner {
//   background-color: $themeColor;
//   border-color: $themeColor;
// }
// :deep .el-checkbox__inner:hover {
//   border-color: $themeColor;
// }
// :deep .el-checkbox__input.is-checked + .el-checkbox__label {
//   color: $themeColor;
// }
</style>
